package com.le.tester.leetcode;


import java.util.ArrayList;
import java.util.List;

/**
 * createTime：2022/6/20 10:31
 * description：比赛中的配对次数
 * 4：4/2场比赛；产生4/2支队伍进行下一轮
 * 3：（3-1）/2场比赛:(3-1）/2+1支队伍
 */
public class NumberOfMatches {
    public int numberOfMatches(int n) {
        int matchNum;
        int teamNum;
        List<Integer> matchNumList = new ArrayList<>();

        teamNum = n * 2;
        while (teamNum != 1) {
            //matchNumList.add(matchNum);
            if (teamNum % 2 == 0) {
                teamNum = teamNum / 2;
            } else {
                teamNum = (teamNum - 1) / 2 + 1;
            }
            if (teamNum % 2 == 0) {
                matchNum = teamNum / 2;
            } else {
                matchNum = (teamNum - 1) / 2;
            }
            matchNumList.add(matchNum);
        }
//        } else {
//            matchNum = (n - 1) / 2;
//            teamNum = (n - 1) / 2 + 1;
//        }
        return matchNumList.stream().mapToInt(Integer::intValue).sum();
    }

    public static void main(String[] args) {
        System.out.println(new NumberOfMatches().numberOfMatches(7));
    }
}
